package com.dk.springmvc.restful.dao.impl;

import com.dk.springmvc.restful.dao.EmpDao;
import com.dk.springmvc.restful.entity.Emp;
import org.springframework.stereotype.Repository;

import java.util.*;

@Repository
public class EmpDaoImpl implements EmpDao {
    private static final Map<Integer, Emp> EMP_DATA;

    // init data
    static {
        EMP_DATA = new HashMap<>();
        EMP_DATA.put(1001, new Emp(1001, "张三", "zs@qwe.com"));
        EMP_DATA.put(1002, new Emp(1002, "李四", "ls@qwe.com"));
        EMP_DATA.put(1003, new Emp(1003, "王二", "we@qwe.com"));
        EMP_DATA.put(1004, new Emp(1004, "王五", "ww@qwe.com"));
        EMP_DATA.put(1005, new Emp(1005, "赵六", "zl@qwe.com"));
        EMP_DATA.put(1006, new Emp(1006, "田七", "tq@qwe.com"));
        EMP_DATA.put(1007, new Emp(1007, "麻子", "mz@qwe.com"));
        EMP_DATA.put(1008, new Emp(1008, "吴一", "wy@qwe.com"));
        EMP_DATA.put(1009, new Emp(1009, "赵八", "zb@qwe.com"));
        EMP_DATA.put(1010, new Emp(1010, "阿斯达", "asd@qwe.com"));
        EMP_DATA.put(1011, new Emp(1011, "汤姆", "tom@qwe.com"));
    }


    @Override
    public List<Emp> queryAllEmp() {
        return EMP_DATA.values().stream().toList();
    }

    @Override
    public Emp queryEmp(Integer empId) {
        return EMP_DATA.get(empId);
    }

    @Override
    public void insertEmp(Emp emp) {
        EMP_DATA.put(emp.getId(),emp);
    }

    @Override
    public void updateEmp(Emp emp) {
        insertEmp(emp);
    }

    @Override
    public void deleteEmp(Integer empId) {
        EMP_DATA.remove(empId);
    }
}
